package com.bytesizedhosting.api.android.darthcrap.screens;

import pl.polidea.customwidget.TheMissingTabActivity;
import pl.polidea.customwidget.TheMissingTabHost;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.bytesizedhosting.api.android.darthcrap.R;
import com.bytesizedhosting.api.android.darthcrap.screens.maintabs.AccountsTab;
import com.bytesizedhosting.api.android.darthcrap.screens.maintabs.NewsTab;
import com.bytesizedhosting.api.android.darthcrap.screens.maintabs.ProfileTab;
import com.bytesizedhosting.api.android.darthcrap.screens.maintabs.SettingsTab;

public class MainScreen extends TheMissingTabActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        TheMissingTabHost objTabHost = this.getTabHost();
        
        addTab(objTabHost,getString(R.string.main_tab_profile) ,R.drawable.ic_tab_profile ,ProfileTab.class );
        addTab(objTabHost,getString(R.string.main_tab_accounts),R.drawable.ic_tab_accounts,AccountsTab.class);
        addTab(objTabHost,getString(R.string.main_tab_news)    ,R.drawable.ic_tab_news    ,NewsTab.class    );
        addTab(objTabHost,getString(R.string.main_tab_settings),R.drawable.ic_tab_settings,SettingsTab.class);
        
        int intChosenTab = 0;
        if (this.getIntent().hasExtra("code")) {
			int intTab = this.getIntent().getExtras().getInt("code");
			if (intTab >= 1 && intTab <= 4) {
				intChosenTab = intTab-1;
			}
		}
        objTabHost.setCurrentTab(intChosenTab);
    }
    
    private void addTab(TheMissingTabHost objTabHost, String strIndiciator, int intIcon, Class<? extends Activity> objActivity) {
    	objTabHost.addTab(objTabHost.newTabSpec(strIndiciator.toLowerCase().replace(' ', '_')).setIndicator(strIndiciator,this.getResources().getDrawable(intIcon)).setContent(new Intent(this,objActivity)));
    }
}